package com.example.adouble.cehuamenu.ui.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.adouble.cehuamenu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的图书
 */
public class MyBookActivity extends AppCompatActivity {

    private ViewPager viewPager;
    private View view1,view2,view3;
    private List<View> views;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_book);

        viewPager = findViewById(R.id.viewpage);
        LayoutInflater layoutInflater = getLayoutInflater();
        view1 = layoutInflater.inflate(R.layout.borrowbook,null);
        view2 = layoutInflater.inflate(R.layout.returnbook,null);
        view3 = layoutInflater.inflate(R.layout.collectionbook,null);
        views = new ArrayList<>();
        views.add(view1);
        views.add(view2);
        views.add(view3);

        PagerAdapter pagerAdapter = new PagerAdapter() {
            @Override
            public int getCount() {
                return views.size();
            }
            @Override
            public void destroyItem(ViewGroup container, int position, Object object){
                container.removeView(views.get(position));
        }
            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }
            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                container.addView(views.get(position));
                return views.get(position);
            }
        };
        viewPager.setAdapter(pagerAdapter);
    }

}
